package top.hmtools.enums;

/**
 * 描述数据库类型的枚举
 * @author HyboJ
 *
 */
public enum EDBType {

//	MySQL(1),
//	Oracle(2),
//	SqlServer(3),
//	SQLite(4);
	
	MySQL(1,"MySql","com.mysql.jdbc.Driver", "jdbc:mysql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=%s", "mysql-connector-java-5.1.44.jar"),
	Oracle(2,"Oracle","oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s:%s", "ojdbc14.jar"),
	PostgreSQL(5,"PostgreSQL","org.postgresql.Driver", "jdbc:postgresql://%s:%s/%s", "postgresql-9.4.1209.jar"),
	SQL_Server(3,"SQL_Server","com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://%s:%s;databaseName=%s", "sqljdbc4-4.0.jar"),
	Sqlite(4,"Sqlite","org.sqlite.JDBC", "jdbc:sqlite:%s", "sqlite-jdbc-3.15.1.jar");
	
	private int typeCode;
	private String name;
    private final String driverClass;
    private final String connectionUrlPattern;
    private final String connectorJarFile;

    EDBType(int typeCode,String name,String driverClass, String connectionUrlPattern, String connectorJarFile) {
    	this.typeCode = typeCode;
        this.driverClass = driverClass;
        this.connectionUrlPattern = connectionUrlPattern;
        this.connectorJarFile = connectorJarFile;
        this.name = name;
    }
    
    public int getTypeCode() {
		return typeCode;
	}

    public String getDriverClass() {
        return driverClass;
    }

    public String getConnectionUrlPattern() {
        return connectionUrlPattern;
    }

    public String getConnectorJarFile() {
        return connectorJarFile;
    }
    
    public String getName() {
		return name;
	}
    
    public static int getTypeCodeByName(String name){
    	int result = -1;
    	for(EDBType ii:EDBType.values()){
    		if(ii.name.trim().equalsIgnoreCase(name.trim())){
    			result =  ii.getTypeCode();
    			break;
    		}
    	}
    	return result;
    }
    
	@Override
	public String toString() {
		return String.valueOf(this.typeCode);
	}

	public static String getDriverClassNameByTypeCode(int db_type) {
		String result=null;
		for(EDBType ii:EDBType.values()){
    		if(ii.typeCode==db_type){
    			result =  ii.getDriverClass();
    			break;
    		}
    	}
		return result;
	}

    /**
    * 方法说明：                    getByTypeCode
    * 输入参数说明：           @param db_type
    * 输入参数说明：           @return
    * 输出参数说明：           EDBType
    *
    **/
    public static EDBType getByTypeCode(int db_type) {
        EDBType result=null;
        for(EDBType ii:EDBType.values()){
            if(ii.typeCode==db_type){
                result =  ii;
                break;
            }
        }
        return result;
    }
}
